﻿carnal_court_sex_interaction = {
    category = interaction_category_friendly

    desc = carnal_court_sex_interaction_desc
    interface_priority = 40
    use_diplomatic_range = no

    is_shown = {
        NOR = {
            has_game_rule = carn_sex_interaction_disabled
            scope:actor = scope:recipient
            has_game_rule = carnal_court_make_love_disabled
        }
        NOR = {
            has_game_rule = carn_sex_interaction_disabled
            scope:actor = scope:recipient
        }
        scope:actor = {
            scope:actor.age >= 18
            is_adult = yes
            NOR = {
                has_trait_with_flag = carn_block_send_sex_interaction
                has_character_flag = carn_block_send_sex_interaction
                has_opinion_modifier = {
                    target = scope:recipient
                    modifier = carn_block_sex_interaction_to_opinion
                }
            }
        }
        scope:recipient = {
            scope:recipient.age >= 18
            is_adult = yes
            NOR = {
                has_trait_with_flag = carn_block_receive_sex_interaction
                has_character_flag = carn_block_receive_sex_interaction
                has_opinion_modifier = {
                    target = scope:actor
                    modifier = carn_block_sex_interaction_from_opinion
                }
            }
        }
        OR = {
            scope:actor = {
                carn_relationship_allows_free_sex_trigger = {
                    PARTNER = scope:recipient
                }
            }
            scope:recipient = {
                carn_is_working_as_prostitute_trigger = yes
            }
        }
    }

    cooldown = { months = carn_sex_interaction_cooldown }

    is_valid_showing_failures_only = {
        scope:actor = {
            carn_can_have_sex_trigger = yes
        }
        scope:recipient = {
            carn_can_have_sex_trigger = yes
        }

        # if this is a paid transaction, actor needs the gold
        trigger_if = {
            limit = {
                scope:recipient = {
                    carn_is_working_as_prostitute_trigger = yes
                }
                NOT = {
                    scope:actor = {
                        carn_relationship_allows_free_sex_trigger = {
                            PARTNER = scope:recipient
                        }
                    }
                }
            }
            scope:actor.gold >= scope:recipient.carn_prostitute_sex_interaction_price_value
        }
    }

    on_accept = {
        scope:actor = {

            # pay money for prostitution, and possibly lose piety if your faith dislikes this
            if = {
                limit = {
                    scope:recipient = {
                        carn_is_working_as_prostitute_trigger = yes
                    }
                    NOT = {
                        carn_relationship_allows_free_sex_trigger = {
                            PARTNER = scope:recipient
                        }
                    }
                }
                pay_short_term_gold = {
                    target = scope:recipient
                    gold = scope:recipient.carn_prostitute_sex_interaction_price_value
                }
                if = {
                    limit = {
                        faith = { NOT = { has_doctrine = carn_doctrine_prostitution_accepted } }
                    }
                    add_piety = minor_piety_loss
                }
            }

            if = {
                limit = {
                    NOT = { has_character_flag = carn_sex_interaction_effect_cd }
                }
				
				# show possible effects from sex scene
                show_as_tooltip = {
                    carn_had_sex_with_effect_v2 = {
                        PARTNER = scope:recipient
                    }
                }

                ### STRESS ###
                if = {
                    limit = {
                        is_attracted_to_gender_of = scope:recipient
                    }
                    stress_impact = {
                        base = minor_stress_impact_loss
                        chaste = activity_stress_gain_impact
                    }
                }
                else = {
                    custom_tooltip = carn_sex_interaction_not_attracted_to_warning_tt
                    stress_impact = {
                        base = major_stress_impact_gain
                    }
                }

                add_character_flag = {
                    flag = carn_sex_interaction_effect_cd
                    months = carn_sex_interaction_cooldown_base
                }
            }
            else = {
                custom_tooltip = carn_sex_interaction_effect_cd_tt
            }

            # request the sex scene
            hidden_effect = {
                # actually fire the sex scene
                carnal_court_sex_scene_effect = {
                        PARTNER = scope:recipient
                }
            }
        }
    }

    auto_accept = yes
}